<template>
  <div class="printClinic">
    <div class="title">{{this.rise}}</div>
    <div class="content">
      <div class="content-title">挂号凭条</div>
      <el-form :label-position="labelPosition" label-width="90px" class="form" width="50%">
        <el-form-item label="姓名：" class="formItemH">
          {{name}}
        </el-form-item>
        <el-form-item label="年龄：" class="formItem">
          {{age}}
        </el-form-item>
        <el-form-item label="性别："class="formItem">
          {{gender}}
        </el-form-item>
        <el-form-item label="医生：" class="formItem">
          {{doctor_name}}
        </el-form-item>
        <el-form-item label="科室：" class="formItem">
          {{department_name}}
        </el-form-item>
        <el-form-item label="挂号类型：" class="formItem">
          {{type_name}}
        </el-form-item>
        <el-form-item label="挂号费：" class="formItem">
          ￥{{receivable_amount | moneyFormat}}
        </el-form-item>
        <el-form-item label="优惠金额：" class="formItem">
          ￥{{discount_amount | moneyFormat}}
        </el-form-item>
        <el-form-item label="实付金额：" class="formItem">
          ￥{{final_amount | moneyFormat}}
        </el-form-item>
        <el-form-item label="收费员：" class="formItem">
          {{username}}
        </el-form-item>
        <el-form-item label="时间：" class="formItem">
          {{dateP | dateFormat}}
        </el-form-item>
      </el-form>
    </div>
    <div class="footer">谢谢惠顾！祝您健康！</div>
  </div>
</template>
<script>
  import {getInfo} from "../../api/user";
  export default {
    props:{
      createData:{}
    },
    data: function () {
      return {
        username:'',
        dateP:'',
        labelPosition: 'left',
        name:'',
        department_name:'',
        gender:'',
        doctor_name:'',
        age:'',
        type_name:'',
        final_amount:'',
        discount_amount:'',
        receivable_amount:''
      }
    },
    created() {
      this.state = JSON.parse(this.$store.getters.printSetting.dic_value)
      this.rise = this.state.receipt_set.rise
      getInfo().then(res => {
        if (res.code == 200) {
          this.username = res.data.real_name
        }
      })
    },
    mounted() {
      var date = new Date();
      var year = date.getFullYear()
      var month = date.getMonth() + 1;
      month = (month < 10 ? '0' + month : month)
      var day = date.getDate();
      this.date = (year.toString() + '-' + month.toString() + '-' + day.toString())
      const hh = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours()
      const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
      const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
      this.dateS = (year.toString() + '-' + month.toString() + '-' + day.toString()+' '+hh+':'+mm+':'+ss)
    },
    watch:{
      createData: {
        handler(newVal,oldVal){
          if(newVal!==oldVal) {
            console.log(newVal)
            this.name=newVal.createData.name
            this.department_name=newVal.createData.department_name
            if(newVal.createData.gender=='0'){
              this.gender='男'
            }else{
              this.gender='女'
            }
            this.doctor_name=newVal.createData.doctor_name
            let arr = newVal.createData.age.toString().split(',')
            if(arr!=''){
              let a = '', a1 = '', a2 = '', a3 = ''
              if (arr[0] == '0') {
                a1 = ''
              } else {
                a1 = arr[0] + '岁'
              }
              if (arr[1] == '0') {
                a2 = ''
              } else {
                a2 = arr[1] + '月'
              }
              if (arr[2] == '0') {
                a3 = ''
              } else {
                a3 = arr[2] + '天'
              }
              a = a1 + a2 + a3
              this.age = a
            }
            this.type_name=newVal.createData.type_name
            this.final_amount=newVal.createData.final_amount
            this.receivable_amount = newVal.createData.receivable_amount
            this.discount_amount = newVal.createData.discount_amount
            this.dateP = newVal.createData.created_at
            console.log(this.dateP)
            if(this.dateP==undefined){
              this.dateP = this.dateS
            }
          }
        },
        deep:true
      }
    },
    methods:{

    }
  }
</script>
<style lang="scss" scoped>
  @import "@/assets/scss/print/invoice.scss";
</style>

